// Drummer
// by Andrea Bianchi
// andreabianchi.alsoplantsfly.com

/*
 Copyright (C) 2009, Andrea Bianchi
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "circle.h"
#include "raster_graphics.h"
using namespace DS;


Circle::Circle ():
pos_(Coord(0,0)), rad_(0), stroke_(NONE), col_(NONE), dcol_(none), velocity_(DEFAULT_VELOCITY)
{}

Circle::Circle (Coord pos, u16 radius, DoubleColor color, Color stroke):
	pos_(pos), rad_(radius), stroke_(stroke), dcol_(color), velocity_(DEFAULT_VELOCITY)
{
	setColor(color);
}


void Circle::draw (ScreenId screen)
{
	circle(screen, pos_.x_, pos_.y_, rad_, stroke_, col_);
}

Circle& Circle::operator=(const Circle& other)
{
	pos_= other.pos_;
	rad_= other.rad_;
	stroke_= other.stroke_;
	col_= other.col_;
	velocity_= other.velocity_;
	dcol_= other.dcol_;
	return *this;
}


BoundingBox Circle::getBB() const
{
	BoundingBox bb;
	bb.s_= (Coord (pos_.x_-rad_, pos_.y_-rad_)); // top left corner
	bb.e_= (Coord (pos_.x_+rad_, pos_.y_+rad_)); // bottom right corner
	return bb;
}

bool Circle::hitTest (Coord c) const
{
  return PA_Distance (pos_.x_, pos_.y_, c.x_, c.y_) <= rad_*rad_;
}


void Circle::setColor(DoubleColor c)
{
	// velocity goes from 20 to 120. rescale it from 0 to 100
	dcol_=c;
	col_= dcol_.computeColor(velocity_-20);	
}

void Circle::setVelocity(u8 velocity)
{
	velocity_=velocity;
	if (velocity_>=MAX_VELOCITY)
	{
		velocity_= MAX_VELOCITY;
	} 
	if (velocity_<=MIN_VELOCITY)
	{
		velocity_= MIN_VELOCITY;
	}
	col_= dcol_.computeColor(velocity_-20);
}